/**
* @ClassName: CategoryAction
* @Description: 
* @author YuYang
* @date 2013-6-5 上午12:54:42
*/
package com.demodis.action;

import com.demodis.domain.Json;
import com.demodis.domain.TblCategory;
import com.demodis.service.CategoryServiceI;
import com.demodis.service.impl.CategoryServiceImpl;
import com.opensymphony.xwork2.ModelDriven;

public class CategoryAction extends BaseAction implements ModelDriven<TblCategory> {

	private static final long serialVersionUID = 1L;
	
	TblCategory category = new TblCategory();
	private CategoryServiceI categoryService = new CategoryServiceImpl();

	public void add() {
		Json json = new Json();
		if (categoryService.save(category)) {
			json.setSuccess(true);
			json.setMsg("添加成功!");
		} else {
			json.setSuccess(false);
			json.setMsg("添加失败!");
		}

		super.writeJson(json);
	}
	
	public void delete() {
		Json json = new Json();
		if (categoryService.delete(category)) {
			json.setSuccess(true);
			json.setMsg("删除成功!");
		} else {
			json.setSuccess(false);
			json.setMsg("删除失败!");
		}

		super.writeJson(json);
	}
	
	public void modify() {
		Json json = new Json();
		if (categoryService.modify(category)) {
			json.setSuccess(true);
			json.setMsg("修改成功!");
		} else {
			json.setSuccess(false);
			json.setMsg("修改失败!");
		}

		super.writeJson(json);
	}
	
	public void query() {
		super.writeJson(categoryService.get());
	}
	
	@Override
	public TblCategory getModel() {
		return category;
	}

}
